﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using System.Collections;


namespace HtmlExtractor.XPathOutput
{
    /// <summary>
    /// Simple&&一个outputPath只对应一个Pageitem，直接替换
    /// </summary>
    class OneOneSimpleProcessor : XmlDocOutputPathProcessor
    {  
        public OneOneSimpleProcessor():base()
        {}
         public OneOneSimpleProcessor(IGrouping<List<string>, IPageItem> inputData):base(inputData)
         { }
        public override bool GetResult(ref XDocument outputData)
        {
            base.GetResult(ref outputData);
            //Simple&&只有一个Pageitem            
            if (InputData.Key.Count == 1 && InputData.Count()==1)
            {
                
                SimpleItem simple = InputData.Single() as SimpleItem;
                if (simple == null)
                    simple = (InputData.Single() as CompositeItem)[0];
                EvaluateXPath(ref outputData,simple.OutputPath,simple.Value);
                return true; ;
            }
            return false;
   
        }
        
    }
}
